package com.hmsm.sys.bean;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import net.sf.json.JSONObject;

public class RelevanceConfig {
	
	private static final Log log = LogFactory.getLog(RelevanceConfig.class);
	
	public static final String RELEVANCE_TYPE_KEY = "relevanceType";

	private String relevanceType = "";
	
	public String getRelevanceType() {
		return relevanceType;
	}

	public void setRelevanceType(String relevanceType) {
		this.relevanceType = relevanceType;
	}

	public RelevanceConfig(){
		
	}
	
	public RelevanceConfig(String relevanceConfig){
		if(relevanceConfig!=null&&relevanceConfig.startsWith("{")&&relevanceConfig.endsWith("}")){
			try {
				JSONObject jsonResult = JSONObject.fromObject(relevanceConfig);
				
				if (jsonResult.containsKey(RELEVANCE_TYPE_KEY)){
					relevanceType = jsonResult.getString(RELEVANCE_TYPE_KEY);
				}
			} catch (Exception e) {
				log.warn("注意：配置信息无效！("+relevanceConfig+")");
			}
		}
	}

	public static String getRelevanceType(String relevanceConfig) {
		return new RelevanceConfig(relevanceConfig).getRelevanceType();
	}
	
	
}
